<?php

/**
 * @author Thanhansoft
 * @email thanhansoft@gmail.com
 * @website http://grouplaptrinh.com
 * @copyright 19/2/2011 13:29
 */

class Index extends Application{
    private $data;
	function __construct(){
        if(!isset($_SESSION['loginok'])){
            $this->loadView('app/view/index/login');
        }
        $this->loadModel('index');
        $this->data['module'] = 'index';
	}
	function index(){
	    if(isset($_SESSION['loginok']) && ($_SESSION['loginok'] == 1)){
	       $this->loadView('app/view/index/logged', $this->data);
        }else{
            $this->loadView('app/view/index/login');
        }
	}
    function check(){
        if(isset($_POST['btnlogin'])){
            $username       = isset($_POST['username']) ? htmlspecialchars(strtolower($_POST['username'])) : '';
            $password       = isset($_POST['password']) ? htmlspecialchars($_POST['password']) : '';
            if($this->model_index->login($username, $password)){
                $_SESSION['loginok'] = 1;
				$_SESSION['username'] = $username;
                header("location:".PATH."/index");
            }else{
                $this->data['error'] = "<script language=\"javascript\">alert(\"Đăng nhập không thành công!\");</script>";
                $this->loadView('app/view/index/login', $this->data);
            }
        }
    }
    function joblist(){
        $this->data['list'] = $this->model_index->joblist($_SESSION['username']);
        $this->loadView('app/view/index/logged', $this->data);
    }
    function incomplete(){
        $this->data['list'] = $this->model_index->jobListtype($_SESSION['username'], 1);
        $this->loadView('app/view/index/logged', $this->data);
    }
    function processing(){
        $this->data['list'] = $this->model_index->jobListtype($_SESSION['username'], 2);
        $this->loadView('app/view/index/logged', $this->data);
    }
    function completed(){
        $this->data['list'] = $this->model_index->jobListtype($_SESSION['username'], 3);
        $this->loadView('app/view/index/logged', $this->data);
    }
    
    function logout(){
        session_unset(); 
		session_destroy();
		header("Location: ".$_SERVER['HTTP_REFERER']);
    }
}

?>